<?php
session_start();
require('../check_login.php');
include(dirname(__FILE__) . '/../config.php');
require_once('products_lib.php');

if (isset($_POST['go'])) {

    add_product($_POST);

}
require_once('../header.php');
?>

<!-- BEGIN CONTAINER -->
<div class="page-container">
    <!-- BEGIN SIDEBAR -->
    <?php require_once('../left_menu.php'); ?>
    <!-- END SIDEBAR -->
    <!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <!-- /.modal -->
            <!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
            <!-- BEGIN STYLE CUSTOMIZER -->

            <!-- END STYLE CUSTOMIZER -->
            <!-- BEGIN PAGE HEADER-->
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->

                    <ul class="page-breadcrumb breadcrumb">

                        <li>
                            <i class="fa fa-home"></i>
                            <a href="dashboard.php">
                                Trang chủ
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>
                        <li>
                            <a href="<?php echo $url ?>/product/products.php">
                                Quản lý hàng hóa
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>
                        <li>
                            <a href="#">
                                Thêm mới
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>

                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="fa fa-reorder"></i>Form nhập liệu
                    </div>

                </div>
                <div class="portlet-body form">
                    <!-- BEGIN FORM-->
                    <form id ='form_add_product' class="horizontal-form" method="post" action="add_product.php">
                        <div class="form-body">
                            <h3 class="form-section">Thông tin sản phẩm</h3>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Tên sản phẩm
                                            <span class="required">*</span>
                                        </label>
                                        <input type="text" class="form-control" id="product_name" name="product_name" value="">
                                        
                                    </div>
                                </div>
                                <!--/span-->
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Mã
                                            
                                        </label>
                                        <input type="text"  class="form-control" id="code" name="code" value="">

                                    </div>
                                </div>
                                <!--/span-->
                            </div>
                            <!--/row-->
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Ngày sản xuất</label>

                                        <input type="text" name="date_manufacture" placeholder="dd/mm/yyyy" class="form-control">
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Ngày hết hạn
                                            
                                        </label>
                                        <input type="text" name="date_expired" placeholder="dd/mm/yyyy" class="form-control">
                                    </div>
                                </div>
                                <!--/span-->

                                <!--/span-->
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Nhà sản xuất
                                            
                                        </label>
                                        <?php 
                                        include(dirname(__FILE__) . '/../manufacturer/manufacturers_lib.php');
                                        $manufacturers=  get_all_manufacturers();
                                        
                                        ?>
                                        
                                        <select name="manufacturer" class="form-control">
                                            <option  value="0">Hãy chọn</option>
                                            <?php 
                                            foreach ($manufacturers as $manufacturer) {
                                             ?>
                                            <option  value="<?php echo $manufacturer['id'] ?>"><?php echo $manufacturer['manufacturer_name'] ?></option>
                                            <?php
                                            }
                                            ?>
                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label class="control-label">Nhà cung cấp</label>
                                        <?php 
                                        include(dirname(__FILE__) . '/../vendor/vendors_lib.php');
                                        $vendors=  get_all_vendors();
                                        
                                        ?>
                                        
                                        <select name="vendor" class="form-control">
                                            <option  value="0">Hãy chọn</option>
                                            <?php 
                                            foreach ($vendors as $vendor) {
                                             ?>
                                            <option  value="<?php echo $vendor['id'] ?>"><?php echo $vendor['vendor_name'] ?></option>
                                            <?php
                                            }
                                            ?>
                                            
                                        </select>
                                    </div>
                                </div>
                                <!--/span-->

                                <!--/span-->
                            </div>
                            
                            <!--/row-->
                            <h3 class="form-section">Mô tả chung</h3>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">

                                        <textarea name="description" rows="3" class="form-control"></textarea>
                                    </div>
                                </div>

                            </div>

                            <!--/row-->

                        </div>
                        <div class="form-actions right">
                            <button class="btn default" type="button">Hủy</button>
                            <button class="btn blue" type="submit" name="go"><i class="fa fa-check"></i> Lưu</button>
                        </div>
                </div>

                <!--/row-->


                </form>
                <!-- END FORM-->
            </div>
        </div>
        <a class="btn default" style="display:none" id="auto_fire_when_add_ok">

        </a>
        <!-- END PAGE CONTENT -->
    </div>
</div>
<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php
require_once('../footer.php');
require_once('../common_script.php');
?>
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="<?php echo $url ?>/assets/scripts/core/app.js"></script>
<script src="<?php echo $url ?>/js/add_product_validation.js"></script>
<script src="<?php echo $url ?>/js/add_product_alert_dialog.js"></script>
<script>
    jQuery(document).ready(function () {
        // initiate layout and plugins
        App.init();
        FormAddContactValidation.init();
        UIAlertDialogApi.init();
<?php
if (isset($_POST['go'])) {
    ?>
            $('#auto_fire_when_add_ok').click();

    <?php
}
?>
    });
</script>
</body>
<!-- END BODY -->
</html>